<?php


namespace App\Admin\Extensions\Renderable;


use App\Models\Department;
use Encore\Admin\Widgets\Table;
use Illuminate\Contracts\Support\Renderable;

class DepartmentUserRenderable implements Renderable
{
    protected $role_type = [0 => '职工', 2 => '科室', 1 => '院级'];

    public function render($key = '')
    {
        $dept = Department::query()->findOrFail($key);
        $table =  new Table(['姓名', '电话', '角色'], $dept->users->map(function ($user) {
            return [$user['name'], $user['mobile'], data_get($this->role_type, $user['role_type'])];
        })->values()->all());
        return $table->render();
    }


}
